package com.yq.day30;

import java.util.concurrent.*;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 09:25
 */
public class Demo03 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //没有个数的线程池
        // ExecutorService ex = Executors.newCachedThreadPool();
        // Future<String> submit = ex.submit(new MyPool());
        //
        // String s = submit.get();
        // System.out.println(s);

        //有个数的
        ExecutorService ex1 = Executors.newFixedThreadPool(2);
        Future<String> submit1 = ex1.submit(new MyPool());
        Future<String> submit2 = ex1.submit(new MyPool());
        Future<String> submit3 = ex1.submit(new MyPool());
        Future<String> submit4 = ex1.submit(new MyPool());


        ex1.shutdownNow();

        String s1 = submit1.get();
        String s2 = submit2.get();
        String s3 = submit3.get();
        String s4 = submit4.get();
        System.out.println("s1 = " + s1);
        System.out.println("s2 = " + s2);
        System.out.println("s3 = " + s3);
        System.out.println("s4 = " + s4);




        //线程池的停止
        // ex.shutdownNow();
        // ex.shutdownNow();


    }
}

class MyPool implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"call start!");
        return "haha";
    }
}